package org.whatever.aha.zjut.platform.service.competition;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.whatever.aha.zjut.base.constant.StatusConstant;
import org.whatever.aha.zjut.platform.entity.competition.Competition;
import org.whatever.aha.zjut.platform.entity.competition.CompetitionTypeInfo;
import org.whatever.aha.zjut.platform.mapper.competition.CompetitionMapper;
import org.whatever.aha.zjut.platform.mapper.competition.CompetitionTypeInfoMapper;
import org.whatever.aha.zjut.platform.vo.competition.CompetitionTypeInfoVo;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @author Vc
 * @version 1.0
 * @Desc
 * @date 2021/09/04 15:04
 */
@Service
@RequiredArgsConstructor
public class CompetitionTypeInfoService {
    final CompetitionTypeInfoMapper competitionTypeInfoMapper;
    final CompetitionMapper competitionMapper;

    /**
     * 获取比赛type
     *
     * @return
     */
    public List<CompetitionTypeInfoVo> getAll(){
        //获得正在进行中的比赛type
        List<Object> objects = competitionMapper.selectObjs(new QueryWrapper<Competition>().eq("comp_status", StatusConstant.COMPETITION_STATUS_ONGOING.getCode()).select("comp_type"));
        Set<Object> types = new HashSet<Object>(objects);

        List<CompetitionTypeInfo> competitionTypeInfos = competitionTypeInfoMapper.selectList(new QueryWrapper<CompetitionTypeInfo>());
        List<CompetitionTypeInfoVo> competitionTypeInfoVos = new ArrayList<CompetitionTypeInfoVo>();
        competitionTypeInfos.forEach(competitionTypeInfo->{
            CompetitionTypeInfoVo competitionTypeInfoVo = new CompetitionTypeInfoVo();
            if(types.contains(competitionTypeInfo.getCompTypeId())){
                competitionTypeInfoVo.setLegal(false);
            }else {
                competitionTypeInfoVo.setLegal(true);
            }
            BeanUtils.copyProperties(competitionTypeInfo, competitionTypeInfoVo);
            competitionTypeInfoVos.add(competitionTypeInfoVo);
        });
        return competitionTypeInfoVos;

    }

}
